package com.qlyl.modules.information.ethadapter;


import com.senlin.ethereum.core.EthClient;
import com.senlin.ethereum.infura.InfuraClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置Spring EthClientBean
 *
 * @author huwei
 */
@Configuration
public class EthClientConfig {

    // 自己的eth节点地址
    @Value("${eth.node}")
    private String ethNode;

    // 钱包存储地址
    @Value("${eth.wallet.filePath}")
    private String walletKeystore;

    // infura的Ropsten测试网
    @Value("${eth.testNet}")
    private boolean testNet = false;

    @Bean
    public EthClient ethClient() {
        if (testNet)
            return EthClient.me(InfuraClient.EndPoint.Ropsten.getNodeAddr()).walletKeystore(this.walletKeystore);
        return EthClient.me(this.ethNode).walletKeystore(this.walletKeystore);
    }

    @Bean
    public InfuraClient.Ropsten ropstenClient() {
        return new InfuraClient.Ropsten();
    }
}
